package controller;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.CityRegionDAO;
import model.VenueDAO;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import beans.UserBean;
import beans.VenueBean;

@WebServlet("/RecentVenuesServlet")
public class RecentVenuesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public RecentVenuesServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		UserBean host = (UserBean)session.getAttribute("currentSessionUser");
		ArrayList<VenueBean> venues = VenueDAO.recentVenues(host);
		Type listOfVenues = new TypeToken<List<VenueBean>>(){}.getType();
		Gson gson = new Gson();

		String s = gson.toJson(venues, listOfVenues);

		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
		response.getWriter().write(new Gson().toJson(venues, listOfVenues));	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
